package com.boliq.demo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.boliq.demo.adapter.MyAdapter;
import com.boliq.demo.adapter.MyAdapter2;
import com.boliq.demo.bean.UserBean;

public class RecyclerViewActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
//    private MyAdapter myAdapter;
    private MyAdapter2 myAdapter2;
    private Button addDataBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);
        mRecyclerView = findViewById(R.id.rv_content);
        addDataBtn = findViewById(R.id.btn_add_data);

        //recycelrview 必须要调用setLayoutManger 才能显示出列表
        LinearLayoutManager manager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(manager);

//        myAdapter = new MyAdapter();
        myAdapter2 = new MyAdapter2();
        //和提供数据及展示的适配器关联
        mRecyclerView.setAdapter(myAdapter2);

        addDataBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserBean bean = new UserBean();

                if(myAdapter2.getData().size()%2==1){
                    bean.setUserName("散户必看：利空来袭，明日大盘走势或让你目瞪口呆！");
                    bean.setHeadID(R.drawable.ic_icon5);
                }else {
                    bean.setUserName("马云没骗人，调控之后房价如葱是真的，看完这些你还想买房吗？");
                    bean.setHeadID(R.drawable.ic_icon6);
                }
                myAdapter2.addData(bean);
            }
        });
    }
}
